import 'package:flutter/cupertino.dart';
import 'package:hitutor/UI/Account/ChangePassword2.dart';
import 'package:hitutor/UI/Member/HelpCenter.dart';
import 'package:hitutor/Util/Global.dart';
import 'package:hitutor/Util/HttpGo.dart';
import 'package:hitutor/Util/MyColor.dart';
import 'package:hitutor/Util/PageUtil.dart';
import 'package:hitutor/Widget/MyButton.dart';
import 'package:hitutor/Widget/MyDialog.dart';
import 'package:hitutor/Widget/MyInput.dart';
import 'package:hitutor/Widget/MyPage.dart';

class ForgetPassword extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ForgetPassword();
  }
}

class _ForgetPassword extends State<ForgetPassword> {
  TextEditingController emailController = TextEditingController();

  send() {
    String email = emailController.text;
    RegExp mobile = new RegExp(r"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$");
    if (!mobile.hasMatch(email)) {
      showToast("請輸入正確的email");
      return;
    }
    HttpGo(context).post("/Member/RetrievePassword", {"email": email}, (data) {
      PageUtil().back(context);
    }, (code, error) => showToast(error));
  }

  @override
  Widget build(BuildContext context) {
    return MyPage(
        "忘記密碼",
        Container(
            padding: EdgeInsets.all(20),
            child: Column(children: [
              Container(
                  alignment: Alignment.centerLeft, child: Text("請選擇您要以下列何種方式重設密碼：", style: TextStyle(fontSize: 11, color: MyColor.Black))),
              Container(
                decoration: Global.getBg(MyColor.F3, 4),
                height: 32,
                margin: EdgeInsets.fromLTRB(0, 8, 0, 48),
                padding: EdgeInsets.only(left: 8),
                child: NormalInput(hintText: "請輸入Email", inputType: NormalInput.Email, fontSize: 12, controller: emailController),
              ),
              Button("送出", height: 32, bgColor: Color(0xff43bacc), width: double.infinity, radius: 4, fontSize: 13, onTap: send),
            ])),
        rightWidgets: [
          TextBtn("幫助中心", margin: EdgeInsets.only(right: 16), height: 40, style: TextStyle(fontSize: 14, color: MyColor.BlueHome),
              onTap: () {
            PageUtil().open(context, HelpCenter());
          })
        ]);
  }
}
